package com.ruoyi.web.controller.gcgl;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.gcgl.domain.GcProjectFlow;
import com.ruoyi.gcgl.service.IGcProjectFlowService;

/**
 * 工程流程图Controller
 * 
 * @author ruoyi
 * @date 2022-11-21
 */
@Controller
@RequestMapping("/gcgl/flow")
public class GcProjectFlowController extends BaseController
{
    private String prefix = "gcgl/flow";

    @Autowired
    private IGcProjectFlowService gcProjectFlowService;

    @RequiresPermissions("gcgl:flow:view")
    @GetMapping()
    public String flow(){
    	
        return prefix + "/flow";
    }

    /**
     * 查询工程流程图列表
     */
    @RequiresPermissions("gcgl:flow:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(GcProjectFlow gcProjectFlow)
    {
        startPage();
        List<GcProjectFlow> list = gcProjectFlowService.selectGcProjectFlowList(gcProjectFlow);
        return getDataTable(list);
    }

    /**
     * 导出工程流程图列表
     */
    @RequiresPermissions("gcgl:flow:export")
    @Log(title = "工程流程图", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(GcProjectFlow gcProjectFlow)
    {
        List<GcProjectFlow> list = gcProjectFlowService.selectGcProjectFlowList(gcProjectFlow);
        ExcelUtil<GcProjectFlow> util = new ExcelUtil<GcProjectFlow>(GcProjectFlow.class);
        return util.exportExcel(list, "工程流程图数据");
    }

    /**
     * 新增工程流程图
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存工程流程图
     */
    @RequiresPermissions("gcgl:flow:add")
    @Log(title = "工程流程图", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public synchronized AjaxResult addSave(GcProjectFlow gcProjectFlow)
    {
        return toAjax(gcProjectFlowService.insertGcProjectFlow(gcProjectFlow));
    }

    /**
     * 修改工程流程图
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        GcProjectFlow gcProjectFlow = gcProjectFlowService.selectGcProjectFlowById(id);
        mmap.put("gcProjectFlow", gcProjectFlow);
        return prefix + "/edit";
    }

    /**
     * 修改保存工程流程图
     */
    @Log(title = "工程流程图", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(GcProjectFlow gcProjectFlow)
    {
        return toAjax(gcProjectFlowService.updateGcProjectFlow(gcProjectFlow));
    }

    /**
     * 删除工程流程图
     */
    @RequiresPermissions("gcgl:flow:remove")
    @Log(title = "工程流程图", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(gcProjectFlowService.deleteGcProjectFlowByIds(ids));
    }
}
